﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using WpfLockScreen.Common;

namespace WpfLockScreen.Views
{
    /// <summary>
    /// LoginView.xaml 的交互逻辑
    /// </summary>
    public partial class DiagView : Window
    {
        DispatcherTimer Timer = new DispatcherTimer();
        public DiagView( )
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void window_Loaded(object sender, RoutedEventArgs e)
        {
            Timer.Interval = new TimeSpan(0, 0, 20);
            Timer.Tick += Timer_Tick;
            Timer.Start();
        }
        private void Timer_Tick(object sender, EventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                Dispatcher.BeginInvoke((Action)delegate ()
                {
                    AutoClose();
                });
            });
        }
        /// <summary>
        ///定时关闭
        /// </summary>
        private void AutoClose()
        {
            if (Timer.IsEnabled)
                Timer.Stop();
            this.Close();
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox a = sender as ComboBox;
            if (a!=null)
            {
                switch (a.Text)
                {
                    case "2小时":
                        CommStatic.RemindSpan = new TimeSpan(2,0,0);
                        break;
                    case "1小时":
                        CommStatic.RemindSpan = new TimeSpan(1, 0, 0);
                        break;
                    case "半小时":
                        CommStatic.RemindSpan = new TimeSpan(0, 30, 0);
                        break;
                    default:
                        break;
                }
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            SetTab.Visibility = Visibility.Collapsed;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            SetTab.Visibility = Visibility.Visible;
        }
    }
}
